<?php
require_once("checklogin.php");
require_once("classQuanTriTin.php");
$qt = new quantritin;
$theloai = $qt->TheLoai('',-1);
$idTin=-1;
if (isset($_GET['idTin'])==false) die('Không biết tin nào'); 
$idTin = $_GET['idTin']; 	
$tin = $qt->ChiTietTin($idTin);
$row_tin = mysql_fetch_assoc($tin);
if (isset($_POST['btnOK'])==true) {
	$qt->ChinhTin($idTin);
	header("location:main.php?p=tintuc_list");
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Tin tuc chinh</title>
<style>
#NewsDetail {
	width: 800px;
	border-top-width: 1px;
	border-right-width: 1px;
	border-bottom-width: 1px;
	border-left-width: 1px;
	border-top-color: #030;
	border-right-color: #030;
	border-bottom-color: #030;
	border-left-color: #030;
}
#from_label {
	height: 38px;
	width: 800px;
	background-color: #FFFFFF;
}

#from_label_left {
	background-image: url(../images/from_logo_left.jpg);
	background-repeat: no-repeat;
	float: left;
	height: 38px;
	width: 19px;
}
#from_label_right {
	background-image: url(../images/from_logo_right.jpg);
	background-repeat: no-repeat;
	float: right;
	height: 38px;
	width: 19px;
}
#from_label_center {
	background-image: url(../images/from_logo_center.jpg);
	background-repeat: repeat-x;
	height: 38px;
	margin-right: 19px;
	margin-left: 19px;
	text-align: center;
	color: #FFFFFF;
	font-family: Arial, Helvetica, sans-serif;
	font-weight: bold;
	padding-top: 5px;
	width: 762px;
}
#NewsDetail td{
	border-bottom-width: 1px;
	border-bottom-style: solid;
	border-bottom-color: #FFFFFF;
	border-top-width: 1px;
	border-top-style: solid;
	border-top-color: #FFFFFF;
}
.left {
	background-color: #FFDDDD;
}
.from_label1 {
	background-color: #FFFFFF;
}
#NewsDetail th {
	width: 90px;
	border-bottom-style: solid;
	border-bottom-color: #FFFFFF;
	background-color: #FFDDDD;
	border-bottom-width: 1px;
	border-top-width: 1px;
	border-top-style: solid;
	border-top-color: #FFFFFF;
}
#NewsDetail .txt{
	color:#FFFFFF;
	background-color:#A8353C;
	width:550px;
	border:solid 1px #963;
	padding-top:3px;
	padding-bottom:3px;
	font-weight: bolder;
}
#NewsDetail #TomTat, #NewsDetail #Content{ height:75px }
#NewsDetail #idTL, #NewsDetail #idLT {
	background-color: #A8353C;
	width: 180px;
	border: 1px solid #009999;
	color: #FFDDDD;
	font-weight: bold;
}
#NewsDetail #btnXoa, #NewsDetail #btnOK {
	color: #99FF00; background-color: #003366;
	width: 80px; padding-top: 3px; padding-bottom: 3px;
}
.white {
	background-color: #FFFFFF;
}
</style>
<script type="text/javascript" src="../Scripts/jquery.js"></script>
<script type="text/javascript" src="ckeditor/ckeditor.js"></script>
<script type="text/javascript" src="ckeditor_tomtat/ckeditor.js"></script>
<script type="text/javascript" src="ckfinder/ckfinder.js"></script>

<script type="text/javascript">
function BrowseServer( startupPath, functionData ){
	var finder = new CKFinder();
	finder.basePath = 'ckfinder/'; //Đường path nơi đặt ckfinder
	finder.startupPath = startupPath; //Đường path hiện sẵn cho user chọn file
	finder.selectActionFunction = SetFileField; // hàm sẽ được gọi khi 1 file được chọn
	finder.selectActionData = functionData; //id của text field cần hiện địa chỉ hình
	finder.selectThumbnailActionFunction = ShowThumbnails; //hàm sẽ được gọi khi 1 file thumnail được chọn	
	finder.popup(); // Bật cửa sổ CKFinder
} //BrowseServer

function SetFileField( fileUrl, data ){
	document.getElementById( data["selectActionData"] ).value = fileUrl;
}
function ShowThumbnails( fileUrl, data ){	
	var sFileName = this.getSelectedFile().name; // this = CKFinderAPI
	document.getElementById( 'thumbnails' ).innerHTML +=
	'<div class="thumb">' +
	'<img src="' + fileUrl + '" />' +
	'<div class="caption">' +
	'<a href="' + data["fileUrl"] + '" target="_blank">' + sFileName + '</a> (' + data["fileSize"] + 'KB)' +
	'</div>' +
	'</div>';
	document.getElementById( 'preview' ).style.display = "";
	return false; // nếu là true thì ckfinder sẽ tự đóng lại khi 1 file thumnail được chọn
}
</script>


<script>
$(document).ready(function(){

	//$("#lang").change(function(){
		//var lang=$(this).val();
		//$("#idTL").load("tintuc_laytheloai.php?lang="+ lang);
	//});
	
	$("#idTL").change(function(){
		var idTL=$(this).val();
		$("#idLT").load("tintuc_layloaitin.php?idTL="+ idTL);
	});

});
</script>
</head>

<body>
<?php ob_start();?>
<form id="formNewsDetail" name="formNewsDetail" method="post" action="">
<table width=800 border=0 align=center cellpadding=4 cellspacing=0 id=NewsDetail>
<tr class="white">
  <th colspan="4" class="white">
    <div id="from_label">
    <div id="from_label_left"></div>
  	<div id="from_label_right"></div>
  	<div id="from_label_center"><span id="header">CHỈNH TIN TỨC</span></div>
  </div>  </th>
  </tr>
<tr><th>Ngôn ngữ</th>
    <td colspan="3">
<select name="lang" id="lang"  class="txt">
<option value="vi" {vi}>Việt Nam </option>
   <option value="en" {en}>English</option>
</select>	 </td>
</tr>
<tr><th>Tiêu đề</th>
    <td colspan=3><input type=text name=TieuDe id=TieuDe class=txt value="{TieuDe}" /></td>
</tr>
<tr><th valign="top">Tóm tắt</th>
    <td colspan=3>
    </td>
</tr>
<tr>
  <th colspan="4">
  <textarea name=TomTat id=TomTat class=txt /></textarea> 
        <script type="text/javascript">
        var editor2 = CKEDITOR.replace( 'TomTat',{
            uiColor : '#9AB8F3',
            language:'vi',
            skin:'office2003',
            
            filebrowserImageBrowseUrl : 'ckfinder/ckfinder.html?Type=Images',
            filebrowserFlashBrowseUrl : 'ckfinder/ckfinder.html?Type=Flash',
            filebrowserImageUploadUrl : 'ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images',
            filebrowserFlashUploadUrl : 'ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Flash',
                        
            toolbar:[
            ['Source','-','Save','NewPage','Preview','-','Templates'],
            ['Cut','Copy','Paste','PasteText','PasteFromWord','-','Print'],
            ['Undo','Redo','-','Find','Replace','-','SelectAll','RemoveFormat'],
            
            ['Bold','Italic','Underline','Strike','-','Subscript','Superscript'],
            ['NumberedList','BulletedList','-','Outdent','Indent','Blockquote','CreateDiv'],
            ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'],
            ['Link','Unlink','Anchor'],
            ['Image','Flash','Table','HorizontalRule','Smiley','SpecialChar','PageBreak'],
            ['Styles','Format','Font','FontSize'],
            ['TextColor','BGColor'],
            ['Maximize', 'ShowBlocks','-','About']
            ]
        });		
        </script>
    	<script>		  		  	
		setTimeout("HienDuLieuTomTat()", 300);		
		function HienDuLieuTomTat(){
			var str= "{TomTat}";			
			var oEditor = CKEDITOR.instances.TomTat;			
			oEditor.setData( str);				
		}
		</script>    
  </th>
  </tr>
<tr><th>Url hình</th>
    <td colspan=3><input type="text" name="urlHinh" id="urlHinh" class="txt" value="{urlHinh}" />
      <input onclick="BrowseServer('Images:/','urlHinh')" type="button" name="btnChonFile" id="btnChonFile" value="..." />
      
      <div id="preview">
           <div id="thumbnails"></div>
       </div>      </td>
</tr>
<tr><th>Ngày đưa</th>
    <td colspan="3"><input type="text" name="Ngay" id="Ngay"  class="txt" value="{Ngay}"/></td>
</tr>
<tr><th>Ẩn hiện</th>
    <td><input type="radio" name="AnHien" id="0" value="0"  {An} />Ẩn
        <input type="radio" name="AnHien" id="1" value="1" {Hien} />Hiện	 </td>
    <td>Nổi bật</td>
    <td>	<input type="radio" name="TinNoiBat" id="TinNoiBat" value="0" 
		{BinhThuong}  /> Bình thường
         <input type="radio" name="TinNoiBat" id="TinNoiBat" value="1" {NoiBat}  /> Nổi bật	 </td>
</tr>
<tr><th>Thể loại</th>
    <td><select name="idTL" id="idTL">

          <?php while ($row_theloai = mysql_fetch_assoc($theloai)) { ?>
        		<option value = "<?php echo $row_theloai['idTL'];?>">
          <?php echo $row_theloai['TenTL'];?>                </option>
            <?php } ?>

         </select>
         <script>
		$(document).ready(function() {
			$("#idTL").val({idTL});
			$("#idLT").load("tintuc_layloaitin.php?idTL={idTL}",null, GanLoaiTin);
		});
		
		function GanLoaiTin() {  $("#idLT").val({idLT}); }		
		</script>    </td>
    <td>Loại tin</td>
    <td><select name="idLT" id="idLT">       
        <option value="0"> Chọn loại tin </option>       
      </select> </td>
</tr>
<tr><td colspan=4> <textarea name=Content id=Content class=txt />

</textarea> 
<script type="text/javascript">
var editor = CKEDITOR.replace( 'Content',{
	uiColor : '#9AB8F3',
	language:'vi',
	skin:'office2003',
	
	filebrowserImageBrowseUrl : 'ckfinder/ckfinder.html?Type=Images',
	filebrowserFlashBrowseUrl : 'ckfinder/ckfinder.html?Type=Flash',
	filebrowserImageUploadUrl : 'ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images',
	filebrowserFlashUploadUrl : 'ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Flash',
			 	
	toolbar:[
	['Source','-','Save','NewPage','Preview','-','Templates'],
	['Cut','Copy','Paste','PasteText','PasteFromWord','-','Print'],
	['Undo','Redo','-','Find','Replace','-','SelectAll','RemoveFormat'],
	
	['Bold','Italic','Underline','Strike','-','Subscript','Superscript'],
	['NumberedList','BulletedList','-','Outdent','Indent','Blockquote','CreateDiv'],
	['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'],
	['Link','Unlink','Anchor'],
	['Image','Flash','Table','HorizontalRule','Smiley','SpecialChar','PageBreak'],
	['Styles','Format','Font','FontSize'],
	['TextColor','BGColor'],
	['Maximize', 'ShowBlocks','-','About']
	]
});		
</script>
<script>		  		  	
setTimeout("HienDuLieu()", 1000);		
function HienDuLieu(){
	var str= "{Content}";			
	var oEditor = CKEDITOR.instances.Content;			
	oEditor.setData( str);				
}
</script>


</td></tr>
</table>
<div align=center>
<input type="reset" name="btnXoa" id="btnXoa" value=" Xoá " />&nbsp;        
   <input type="submit" onclick="return alert('Chỉnh thành công');" name="btnOK" id="btnOK" value="  OK  " />
</div>
</form>
<?php
$str=ob_get_clean(); 
$str = str_replace("{TieuDe}" , $row_tin['TieuDe'],$str);
$str = str_replace("{TomTat}" , mysql_real_escape_string($row_tin['TomTat']),$str);
$str = str_replace("{urlHinh}" , $row_tin['urlHinh'],$str);
$str = str_replace("{Ngay}" , $row_tin['Ngay'],$str);
$str = str_replace("{Content}",mysql_real_escape_string($row_tin['Content']),$str);

$str = str_replace("{idTL}" , $row_tin['idTL'],$str);
$str = str_replace("{idLT}" , $row_tin['idLT'],$str);

$str = str_replace("{An}" , ($row_tin['AnHien']==0)? "checked=checked":"",$str);	
$str = str_replace("{Hien}" , ($row_tin['AnHien']==1)? "checked=checked":"",$str);

$str = str_replace("{BinhThuong}" , ($row_tin['TinNoiBat']==0)? "checked=checked":"",$str);
$str =str_replace("{NoiBat}",($row_tin['TinNoiBat']==1)? "checked=checked":"",$str);
$str=str_replace("{vi}",($row_tin['lang']=='vi')? "selected=selected":"",$str);
$str=str_replace("{en}",($row_tin['lang']=='en')? "selected=selected":"",$str);

$str = str_replace("{idTin}" , $row_tin['idTin'],$str);
echo $str;
?>

</body>
</html>
